<!DOCTYPE html>
<html lang="zh-cn" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
</head>
<body>
<div class="panel admin-panel" id="categoryDiv">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加分类</strong></div>
    <div class="body-content">
        <form method="post"  class="form-x">
            <input type="hidden" name="id" v-model="category.id">

            <div class="form-group">
                <div class="label">
                    <label>分类名称：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" v-model="category.categoryName" name="categoryName" data-validate="required:请输入名称" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="clear"></div>



            <div class="form-group">
                <div class="label">
                    <label>排序：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" name="orderNo"    v-model="category.orderNo" data-validate="number:排序必须为数字" />
                    <div class="tips"></div>

                </div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit" @click="submit()"> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    const app = new Vue({
        el:'#categoryDiv',
        data:{
            category:{

            }
        },
        methods:{
            submit(){
                axios.post('http://127.0.0.1:8081/category/save',this.category
                ).then(resp=>{
                    if (resp.data=='ok'){
                        alert('添加成功');
                        location.href='http://127.0.0.1:81/category_list.html';
                    } else {
                        alert('添加失败');
                    }
                })
            },
            findById(id){
                axios.get('http://127.0.0.1:8081/category/findById?id='+id).then(resp=>{
                    this.category=resp.data;
                })
            }
        },
        created(){
            //拆开地址，找到id
            let id= location.search.split("=")[1]
            this.findById(id);
        }
    })
</script>
<script src="/js/verify.js"></script>
</body>
</html>